<!DOCTYPE html>
<html lang="en" class="x-admin-sm">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>回复意见反馈</title>
    <link rel="stylesheet" href="./assets/layui/css/layui.css" media="all" />
    <script type="text/javascript" src="./assets/layui/layui.js"></script>
</head>

<body class="childrenBody">
    <div id="app">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>回复意见反馈</legend>
        </fieldset>
        <div class="layui-form" style="width: 80%;">
            <div class="layui-form-item"><label class="layui-form-label">内容</label>
                <div class="layui-input-block"><input type="text" class="layui-input" id="contents" v-model="contents"
                        placeholder="请输入内容" />
                </div>
            </div>
            <div class="layui-form-item"><label class="layui-form-label">管理回复</label>
                <div class="layui-input-block">
                   <textarea class="layui-input" id="reps" v-model="reps" style="height: 220px;" placeholder="请输入管理回复"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" @click.prevent="update()">提交保存</button>
                    <button class="layui-btn" @click.prevent="reset()">取消重置</button>
                </div>
            </div>
        </div>
    </div>


    <script type="text/javascript" src="./assets/js/axios.min.js"></script>
    <script type="text/javascript" src="./assets/js/vue.js"></script>
    <script type="text/javascript" src="./assets/js/jquery.min.js"></script>
    <script type="text/javascript">
      const vue = new Vue({
            el: '#app', // 绑定作用域
            data: { //定义数据用于vue的双向绑定
                complainsid: '',
                contents: '', // 内容
                reps: '', // 管理回复
            },
            methods: {
                getUrlParam: function() {
                    var name, value;
                    var str = location.href; // 取得整个地址栏
                    var num = str.indexOf("?"); // 定位参数起始位置
                    str = str.substr(num + 1); // 取得所有参数 
                    var arr = str.split("&"); // 各个参数放到数组里
                    for (var i = 0; i < arr.length; i++) {
                        num = arr[i].indexOf("=");
                        if (num > 0) {
                            name = arr[i].substring(0, num);
                            value = arr[i].substr(num + 1);
                            this.complainsid = value; // 确认主键参数
                        }
                    }
                },
                loadPage: function() {
                    let _this = this;
                    axios.get('http://localhost:8080/vue_gxhfztjxt/complains/getComplainsById.action?id=' + _this.complainsid).then(result => {
                        _this.contents = result.data.contents;
                        _this.reps = result.data.reps;
                    });
                },
                reset: function() {
                    this.loadPage();
                },
                update: function() {
                    let _this = this;
                    var data = {
                        complainsid: _this.complainsid,
                        contents: _this.contents,
                        reps: _this.reps,
                    };
                    axios.post('http://localhost:8080/vue_gxhfztjxt/complains/updateComplains.action', data).then(result => {
                        if (result.data.code > 0) {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();
                            parent.layer.close(index);
                        } else {
                            alert('修改失败');
                        }
                    });
                },
            },

            created() { // 生命周期相关的函数
                this.getUrlParam();
                this.loadPage();
                let _this = this;
            },
        })
	</script>

</body>

</html>


